package com.hengtuo.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengtuo.kaiyuanzhongguo.R;
import com.hengtuo.util.ImageLoderUtils;
import com.hengtuo.vo.Usered;

import java.util.List;

/**
 * Created by Administrator on 2016/5/13.
 */
public class FinderAdapter extends BaseAdapter{

    private Context context;
    private List<Usered> list;

    public FinderAdapter(Context context, List<Usered> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if(convertView==null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_finder,null);
            viewHolder.head = (ImageView)convertView.findViewById(R.id.adapter_finder_head);
            viewHolder.sex = (ImageView)convertView.findViewById(R.id.adapter_finder_sex);
            viewHolder.name = (TextView)convertView.findViewById(R.id.adapter_finder_name);
            viewHolder.address = (TextView)convertView.findViewById(R.id.adapter_finder_adress);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        // 圆形头像
        new ImageLoderUtils().getRoundImage(list.get(position).getPortrait(), viewHolder.head);
        viewHolder.name.setText(list.get(position).getName());
        viewHolder.address.setText(list.get(position).getFrom());

        if (list.get(position).getGender().equals("女")){
            Log.e("gril", list.get(position).getGender());
            viewHolder.sex.setBackgroundResource(R.mipmap.userinfo_icon_female);
        }else if(list.get(position).getGender().equals("男")){
            Log.e("boy", list.get(position).getGender());
            viewHolder.sex.setBackgroundResource(R.mipmap.userinfo_icon_male);
        }

        return convertView;
    }

    class ViewHolder{

        ImageView head,sex;
        TextView name,address;
    }

}
